﻿using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;

namespace MiniApi;

public static class ProgramExpand
{
	public static WebApplication? AddUrls(this WebApplication app, string url)
	{
		app.Urls.Add(url);
		return app;
	}

	public static void MinialApiBase(this IEndpointRouteBuilder app)
	{
		app.MapGet("get-example", () => "Hello World");
	}

	public static void ReturnJson(this IEndpointRouteBuilder app)
	{
		app.MapGet("json-example", (string name) => Results.Ok(new {name}));

		app.MapGet("param-example/{age}", (int age) => Results.Ok(new { age }));

		app.MapGet("get-param-binding/{age}", ([FromRoute]int age, [FromQuery(Name = "query")] string name, [FromServices] GuidGenerator generator) => Results.Ok(new { age, name, guid = generator.Generato() }));

		app.MapPost("post-param-binding", ([FromBody] Person person) => Results.Ok(person));

		app.MapGet("htppcontext", (HttpContext context) => Results.Ok(context.Items));

		app.MapGet("request", async (HttpRequest request, HttpResponse response) => await response.WriteAsync(request.QueryString.Value));

		app.MapGet("userinfo", (ClaimsPrincipal claims) => Results.Ok(claims.Identity));
	}
}
